package com.nkym.wypan.listener;/*
 * @ClassName StartedListenner
 * @Desc TODO
 * @Author 19637
 * @Date 2023/6/5 15:02
 * @Version 1.0
 */

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ansi.AnsiColor;
import org.springframework.boot.ansi.AnsiOutput;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class StartedListener implements ApplicationListener<ApplicationReadyEvent> {

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {

        ConfigurableApplicationContext context = event.getApplicationContext();
        String port = context.getEnvironment()
                .getProperty("server.port");
        String prefix = context.getEnvironment().getProperty("server.servlet.context-path");
        String uri = "http://127.0.0.1:" + port + prefix;
        log.info(AnsiOutput.toString(AnsiColor.BLUE, "Wy pan server started at :", uri));
        String profile = context.getEnvironment().getActiveProfiles()[0];
        if ( "dev".equals(profile)) {
            log.info(AnsiOutput.toString(AnsiColor.BLUE, "Wy pan Doc  started at :", uri+"/doc.html"));
        }
    }
}
